package com.cyurs.netty.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/16
 */
public class MappedByteBufferDemo {
    public static void main(String[] args) throws  Exception{
        RandomAccessFile randomAccessFile = new RandomAccessFile("a.txt", "rw");
        FileChannel channel = randomAccessFile.getChannel();


        MappedByteBuffer mappedByteBuffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 5);

        mappedByteBuffer.put(0, (byte) 'W');
        mappedByteBuffer.put(4, (byte) 'C');

        randomAccessFile.close();

    }
}
